#include <iostream>
#include <memory>

#include "ThreadPool.hpp"
#include "Task.hpp"
#include "Log.hpp"

int main()
{

    //单例模式，存在线程安全（如果10个线程同时通过判断，就会出问题，那么就需要加锁）
    // std::unique_ptr<ThreadPool<Task>> tp(new ThreadPool<Task>());
    // tp->Start();
    ThreadPool<Task>::GetInstance()->Start();
    while (true)
    {
        int data_x = rand() % 10 + 1;
        usleep(rand() % 123);
        int data_y = rand() % 10 + 1;
        int op = rand() % opres.size();

        Task t(data_x, data_y, opres[op]);
        ThreadPool<Task>::GetInstance()->Push(t);
        lg(Info,"Task Create : %s " , t.PrintTask().c_str());
        // std::cout <<"Task done : " << t.PrintTask() << std::endl;
        // sleep(1);
        usleep(100);
    }

    ThreadPool<Task>::GetInstance()->Wait();
    return 0;
}